package com.youxin.busfoundation.log.kafka;

import org.apache.log4j.Level;

/**
 * 
 * @author yingde.cao
 *
 */
public class KafkaLevel extends Level {

	private static final long serialVersionUID = 124133254345L;
	/**
	 * Value of security level. This value is slightly higher than
	 * {@link org.apache.log4j.Priority#INFO_INT}.
	 */
	public static final int KAFKA_LEVEL_INT = Level.FATAL_INT + 1;

	/**
	 * {@link Level} representing my log level
	 */
	public static final Level KAFKA = new KafkaLevel(KAFKA_LEVEL_INT, "KAFKA", -1);

	private static final String KAFKA_MSG = "KAFKA";

	/**
	 * Default constructor.
	 */
	protected KafkaLevel(int arg0, String arg1, int arg2) {
		super(arg0, arg1, arg2);

	}

	/**
	 * Checks whether <code>sArg</code> is "SECURITY" level. If yes then returns
	 * {@link SecurityLevel#SECURITY}, else calls
	 * {@link SecurityLevel#toLevel(String, Level)} passing it
	 * {@link Level#DEBUG} as the defaultLevel
	 *
	 * @see Level#toLevel(java.lang.String)
	 * @see Level#toLevel(java.lang.String, org.apache.log4j.Level)
	 *
	 */
	public static Level toLevel(String sArg) {
		if (sArg != null && sArg.toUpperCase().equals(KAFKA_MSG)) {
			return KAFKA;
		}
		return (Level) toLevel(sArg, Level.DEBUG);
	}

	/**
	 * Checks whether <code>val</code> is
	 * {@link SecurityLevel#SECURITY_LEVEL_INT}. If yes then returns
	 * {@link SecurityLevel#SECURITY}, else calls
	 * {@link SecurityLevel#toLevel(int, Level)} passing it {@link Level#DEBUG}
	 * as the defaultLevel
	 *
	 * @see Level#toLevel(int)
	 * @see Level#toLevel(int, org.apache.log4j.Level)
	 *
	 */
	public static Level toLevel(int val) {
		if (val == KAFKA_LEVEL_INT) {
			return KAFKA;
		}
		return (Level) toLevel(val, Level.DEBUG);
	}

	/**
	 * Checks whether <code>val</code> is
	 * {@link SecurityLevel#SECURITY_LEVEL_INT}. If yes then returns
	 * {@link SecurityLevel#SECURITY}, else calls
	 * {@link Level#toLevel(int, org.apache.log4j.Level)}
	 *
	 * @see Level#toLevel(int, org.apache.log4j.Level)
	 */
	public static Level toLevel(int val, Level defaultLevel) {
		if (val == KAFKA_LEVEL_INT) {
			return KAFKA;
		}
		return Level.toLevel(val, defaultLevel);
	}

	/**
	 * Checks whether <code>sArg</code> is "SECURITY" level. If yes then returns
	 * {@link SecurityLevel#SECURITY}, else calls
	 * {@link Level#toLevel(java.lang.String, org.apache.log4j.Level)}
	 *
	 * @see Level#toLevel(java.lang.String, org.apache.log4j.Level)
	 */
	public static Level toLevel(String sArg, Level defaultLevel) {
		if (sArg != null && sArg.toUpperCase().equals(KAFKA_MSG)) {
			return KAFKA;
		}
		return Level.toLevel(sArg, defaultLevel);
	}
	
}